#pragma once

#include "GSE_DataSet.h"
using namespace std;
namespace GSE
{
	class CField
	{
	public:
		CField(const char * strName) : mName(strName) {}
		const char * Name() { return mName.c_str(); }

		bool operator < (const CField & m) const
		{
			return mName < m.mName;
		}

	private:
		string mName;
	};

	class CFieldMap
	{
	public:
		typedef map<CField,uint> Fields;
	public:
		virtual ~CFieldMap() {}

		uint operator[](const char * strFieldName)
		{
			std::string temp(strFieldName);
			boost::to_lower(temp);
			Fields::iterator i = mFieldMap.find(strFieldName);
			if (i != mFieldMap.end())
				return i->second;
			string errText ="Field :";
			errText += strFieldName;
			errText += " Not Exist!";
			throw range_error(errText.c_str());
		}
		uint FieldCount() const {return mFieldMap.size();}
	protected:
		map<CField,uint> mFieldMap;
	};



	class CRow : public IRow
	{
	public:
		typedef shared_ptr<CRow> pointer;

		CRow(CFieldMap * );
		virtual uint Size() const;
		virtual void Push(const char * strVal,uint uLen);
		virtual const char * operator [] (int uIndex) const;
		virtual const char * operator [] (const char * strFieldName) const;


	private:
		vector<string> mDatas;
		CFieldMap * mFieldMap;
	};

	class CDataSet: public IDataSet
	{
	public:
		virtual uint Size() const
		{
			return m_Rows.size();
		}
		virtual uint FieldCount() const = 0;
		virtual uint FieldIndex(const char * strFieldName) const = 0;
		virtual const IRow & operator [] (int index) const = 0;

	protected:
		vector<CRow::pointer> m_Rows;
	};
}